package com.atguigu.gmall.payment.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Map;

@Component
public class PaymentContext {
    private final Map<String, PaymentStrategy> paymentStrategies;

    @Autowired
    public PaymentContext(Map<String, PaymentStrategy> paymentStrategies) {
        this.paymentStrategies = paymentStrategies;
    }

    public void executePay(String paymentType, BigDecimal amount) {
        paymentStrategies.get(paymentType).pay(amount);
    }

    public void executeRefund(String paymentType, BigDecimal amount) {
        paymentStrategies.get(paymentType).refund(amount);
    }

    public String executeCallback(String paymentType, Map<String, String> paramsMap) {
        return paymentStrategies.get(paymentType).callback(paramsMap);
    }

}
